/**
 *****************************************************************************
 * DESC ：. 
 * Author : Junwei Zhang 
 * CREATEDATE ：2012-8-5 
 * MODIFYLIST ：       	Name 			 Date 			Reason/Contents
 * 				------------------------------------------------------ 
 * 				 	Junwei Zhang     2012-8-5		Created.
 ****************************************************************************
 **/
package com.me.client;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Enumeration;

import javax.swing.AbstractButton;
import javax.swing.AbstractListModel;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * 
 * <br/>
 * 上午10:10:19 2012-8-5
 * 
 * @Author <a href="mailto:mestudying@sina.com">Junwei Zhang</a><br/>
 **/
public class JTalkFrontSettings extends JFrame {
	private static final long serialVersionUID = 1L;
	private JTalkClientFront parent = null;
	private JPanel jPanelBottom = null;
	private JPanel jPanelCenter = null;
	private JPanel jPanelContent = null;
	private JButton jButtonOK = null;
	private JButton jButtonCancel = null;
	private JList jListPropertyPages = null;
	private JScrollPane jScrollPaneProperty = null;
	private JSplitPane jSplitPaneProperty = null;
	private JPanel jPanelAccount = null;
	private JLabel jLabelUserName = null;
	private JTextField jTextFieldUserName = null;
	private JLabel jLabelPassword = null;
	private JPasswordField jPasswordField = null;
	private JCheckBox jCheckBoxSavePassword = null;
	private JPanel jPanelServer = null;
	private JLabel jLabelServerName = null;
	private JTextField jTextFieldServerIP = null;
	private JLabel jLabelServerPort = null;
	private JTextField jTextFieldServerPort = null;
	private JCheckBox jCheckBoxUseSSL = null;
	private JPanel jPanelApps = null;
	private JLabel jLabelBrowser = null;
	private JTextField jTextFieldBrowser = null;
	private JLabel jLabelMail = null;
	private JTextField jTextFieldMail = null;
	private JPanel jPanelNote = null;
	private ButtonGroup buttonGroupNote = null;
	private JPanel jPanelUserList = null;
	private JLabel jLabelUserListInfo = null;
	private JRadioButton jRadioButtonUserListNone = null;
	private JRadioButton jRadioButtonUserListToFront = null;
	private JRadioButton jRadioButtonUserListNotiBox = null;
	private JRadioButton jRadioButtonUserListBeep = null;
	private JPanel jPanelLookAndFeel = null;
	private JPanel jPanelPlafs = null;
	private JComboBox jComboBoxLooks = null;
	private JPanel jPanelColors = null;
	private JLabel jLabelBGColor = null;
	private JButton jButtonBGColor = null;
	private JLabel jLabelTXColor = null;
	private JButton jButtonTxColor = null;
	private JButton jButtonPlugins = null;
	private JButton jButtonPluginsDir = null;
	private JPanel jPanelPlugins = null;
	private JLabel jLabelPluginsDir = null;
	private JTextField jTextFieldPluginsDir = null;
	private ClassLoader cl = null;
	private boolean onInit = true;

	public JTalkFrontSettings(JTalkClientFront parent) {
		// TODO Auto-generated constructor stub
		this.parent = parent;
		this.cl = JTalkFrontSettings.class.getClassLoader();
		this.initComponents();
		this.setupElements();
		this.setSize(500, 320);
		this.jListPropertyPages.setSelectedIndex(0);
		this.showPropertyPanel(0);
		this.setLocationRelativeTo(parent);
		this.getRootPane().setDefaultButton(this.jButtonOK);
		this.onInit = false;
	}

	/**
	 * 显示设置项.
	 * 
	 * @param pane
	 */
	private void showPropertyPanel(int pane) {
		// TODO Auto-generated method stub
		this.jPanelAccount.setVisible(false);
		this.jPanelServer.setVisible(false);
		this.jPanelApps.setVisible(false);
		this.jPanelNote.setVisible(false);
		this.jPanelLookAndFeel.setVisible(false);
		this.jPanelPlugins.setVisible(false);
		switch (pane) {
		case 0:
			this.jPanelAccount.setVisible(true);
			break;
		case 1:
			this.jPanelServer.setVisible(true);
			break;
		case 2:
			this.jPanelApps.setVisible(true);
			break;
		case 3:
			this.jPanelNote.setVisible(true);
			break;
		case 4:
			this.jPanelLookAndFeel.setVisible(true);
			break;
		case 5:
			this.jPanelPlugins.setVisible(true);
			break;
		default:
			break;
		}
	}

	/**
	 * 初始化组件.
	 */
	private void initComponents() {
		// TODO Auto-generated method stub
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				closeWindow();
			}
		});
		jPanelCenter = new JPanel();
		jPanelCenter.setLayout(new BorderLayout());
		jListPropertyPages = new JList();
		jListPropertyPages.setModel(new AbstractListModel() {
			private static final long serialVersionUID = 1L;
			String[] properties = { "Login", "Server", "Apps", "Notification", "Look", "Plugins" };

			@Override
			public int getSize() {
				return properties.length;
			}

			@Override
			public Object getElementAt(int index) {
				return properties[index];
			}
		});
		jListPropertyPages.addListSelectionListener(new ListSelectionListener() {
			@Override
			public void valueChanged(ListSelectionEvent e) {
				listPropertyChanged(e);
			}
		});
		jListPropertyPages.setCellRenderer(new MyCellRenderer());
		jScrollPaneProperty = new JScrollPane();
		jScrollPaneProperty.setViewportView(jListPropertyPages);
		jSplitPaneProperty = new JSplitPane();
		jSplitPaneProperty.setLeftComponent(jScrollPaneProperty);
		jPanelContent = new JPanel();
		jPanelContent.setLayout(new BoxLayout(jPanelContent, BoxLayout.Y_AXIS));

		/** -------------------------Account Info---------------------------- */
		jPanelAccount = new JPanel();
		jPanelAccount.setLayout(null);
		jLabelUserName = new JLabel();
		jLabelUserName.setText("User Name:");
		jLabelUserName.setBounds(0, 10, 110, 30);
		jLabelUserName.setHorizontalAlignment(SwingConstants.RIGHT);
		jPanelAccount.add(jLabelUserName);
		jTextFieldUserName = new JTextField();
		jTextFieldUserName.setToolTipText("Your JTalk User Name.");
		jTextFieldUserName.setBounds(120, 10, 123, 30);
		jPanelAccount.add(jTextFieldUserName);
		jLabelPassword = new JLabel();
		jLabelPassword.setText("User Password:");
		jLabelPassword.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelPassword.setBounds(0, 50, 110, 30);
		jPanelAccount.add(jLabelPassword);
		jPasswordField = new JPasswordField();
		jPasswordField.setBounds(120, 50, 123, 30);
		jPanelAccount.add(jPasswordField);
		jCheckBoxSavePassword = new JCheckBox();
		jCheckBoxSavePassword.setText("Save Password");
		jCheckBoxSavePassword.setToolTipText("Save your password in configuration file.");
		jCheckBoxSavePassword.setBounds(120, 90, 120, 26);
		jPanelAccount.add(jCheckBoxSavePassword);
		jPanelContent.add(jPanelAccount);

		/** -------------------------Server Info---------------------------- */
		jPanelServer = new JPanel();
		jPanelServer.setLayout(null);
		jLabelServerName = new JLabel();
		jLabelServerName.setText("Server Name:");
		jLabelServerName.setBounds(0, 10, 110, 30);
		jLabelServerName.setHorizontalAlignment(SwingConstants.RIGHT);
		jPanelServer.add(jLabelServerName);
		jTextFieldServerIP = new JTextField();
		jTextFieldServerIP.setToolTipText("Servers IP-Address");
		jTextFieldServerIP.setBounds(120, 10, 123, 30);
		jPanelServer.add(jTextFieldServerIP);
		jLabelServerPort = new JLabel();
		jLabelServerPort.setText("Server Port:");
		jLabelServerPort.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelServerPort.setBounds(0, 50, 110, 30);
		jPanelServer.add(jLabelServerPort);
		jTextFieldServerPort = new JTextField();
		jTextFieldServerPort.setText("Server Port Number:");
		jTextFieldServerPort.setBounds(120, 50, 123, 30);
		jPanelServer.add(jTextFieldServerPort);
		jCheckBoxUseSSL = new JCheckBox();
		jCheckBoxUseSSL.setText("Use SSL");
		jCheckBoxUseSSL.setToolTipText("Use secure connection to server");
		jCheckBoxUseSSL.setBounds(120, 90, 120, 26);
		jPanelServer.add(jCheckBoxUseSSL);
		jPanelContent.add(jPanelServer);

		/** -------------------------Application Info---------------------------- */
		jPanelApps = new JPanel();
		jPanelApps.setLayout(null);
		jLabelBrowser = new JLabel();
		jLabelBrowser.setText("Web Browser:");
		jLabelBrowser.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelBrowser.setBounds(0, 10, 110, 30);
		jPanelApps.add(jLabelBrowser);
		jTextFieldBrowser = new JTextField();
		jTextFieldBrowser.setText("Mozilla");
		jTextFieldBrowser.setToolTipText("Full path to your favourate browser");
		jTextFieldBrowser.setBounds(120, 10, 123, 30);
		jPanelApps.add(jTextFieldBrowser);
		jLabelMail = new JLabel();
		jLabelMail.setText("Mail Client:");
		jLabelMail.setHorizontalAlignment(SwingConstants.RIGHT);
		jLabelMail.setBounds(0, 50, 110, 30);
		jPanelApps.add(jLabelMail);
		jTextFieldMail = new JTextField();
		jTextFieldMail.setText("kmail");
		jTextFieldMail.setToolTipText("Full path to your favourite e-mail client");
		jTextFieldMail.setBounds(120, 50, 123, 30);
		jPanelApps.add(jTextFieldMail);
		jPanelContent.add(jPanelApps);

		/** -------------------------Notification Info---------------------------- */
		jPanelNote = new JPanel();
		buttonGroupNote = new ButtonGroup();
		jPanelUserList = new JPanel();
		jPanelUserList.setLayout(new GridLayout(5, 0));
		jPanelUserList.setBorder(new TitledBorder("New Mail Notification (Main Window)"));
		jLabelUserListInfo = new JLabel();
		jLabelUserListInfo.setBackground(SystemColor.info);
		jLabelUserListInfo.setText("Occures only, if no chat window is open for affected user.");
		jLabelUserListInfo.setOpaque(true);
		jPanelUserList.add(jLabelUserListInfo);
		jRadioButtonUserListNone = new JRadioButton();
		jRadioButtonUserListNone.setText("None (only an envelope icon)");
		buttonGroupNote.add(jRadioButtonUserListNone);
		jPanelUserList.add(jRadioButtonUserListNone);
		jRadioButtonUserListToFront = new JRadioButton();
		jRadioButtonUserListToFront.setText("Bring main window to front (get focus)");
		buttonGroupNote.add(jRadioButtonUserListToFront);
		jPanelUserList.add(jRadioButtonUserListToFront);
		jRadioButtonUserListNotiBox = new JRadioButton();
		jRadioButtonUserListNotiBox.setText("Show a nice notification box (in background)");
		buttonGroupNote.add(jRadioButtonUserListNotiBox);
		jPanelUserList.add(jRadioButtonUserListNotiBox);
		jRadioButtonUserListBeep = new JRadioButton();
		jRadioButtonUserListBeep.setText("Beep");
		buttonGroupNote.add(jRadioButtonUserListBeep);
		jPanelUserList.add(jRadioButtonUserListBeep);
		jPanelUserList.getAccessibleContext().setAccessibleName("Main Window");
		jPanelNote.add(jPanelUserList);
		jPanelContent.add(jPanelNote);

		/** -------------------------Look And Feel Info---------------------------- */
		jPanelLookAndFeel = new JPanel();
		jPanelLookAndFeel.setLayout(new GridLayout(2, 1));
		jPanelPlafs = new JPanel();
		jPanelPlafs.setBorder(new TitledBorder("Look And Feel"));
		jComboBoxLooks = new JComboBox();
		jComboBoxLooks.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				switchLookAndFeel();
			}
		});
		jPanelPlafs.add(jComboBoxLooks);
		jPanelLookAndFeel.add(jPanelPlafs);
		jPanelColors = new JPanel();
		jPanelColors.setLayout(new GridLayout(2, 2));
		jPanelColors.setBorder(new TitledBorder("Colors"));
		jLabelBGColor = new JLabel();
		jLabelBGColor.setText("Chat Background Color:");
		jPanelColors.add(jLabelBGColor);
		jButtonBGColor = new JButton();
		jButtonBGColor.setText("Color...");
		jButtonBGColor.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				selectBGColor();
			}
		});
		jPanelColors.add(jButtonBGColor);
		jLabelTXColor = new JLabel();
		jLabelTXColor.setText("Chat Text Color:");
		jPanelColors.add(jLabelTXColor);
		jButtonTxColor = new JButton();
		jButtonTxColor.setText("Color...");
		jButtonTxColor.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				selectTXColor();
			}
		});

		jPanelColors.add(jButtonTxColor);
		jPanelLookAndFeel.add(jPanelColors);
		jPanelContent.add(jPanelLookAndFeel);

		/** -------------------------Plug-ins Info---------------------------- */
		jPanelPlugins = new JPanel();
		jPanelPlugins.setLayout(null);
		jLabelPluginsDir = new JLabel();
		jLabelPluginsDir.setText("Plugin Dir:");
		jLabelPluginsDir.setBounds(0, 10, 110, 30);
		jLabelPluginsDir.setHorizontalAlignment(SwingConstants.RIGHT);
		jPanelPlugins.add(jLabelPluginsDir);
		jTextFieldPluginsDir = new JTextField();
		jTextFieldPluginsDir.setText(System.getProperty("user.home") + File.separator + "jt_plugins");
		jTextFieldPluginsDir.setToolTipText("Full path to the plugin directory");
		jTextFieldPluginsDir.setEditable(false);
		jTextFieldPluginsDir.setBounds(120, 10, 160, 30);
		jPanelPlugins.add(jTextFieldPluginsDir);
		jButtonPlugins = new JButton();
		jButtonPlugins.setText("Plugin Overview");
		jButtonPlugins.setBounds(120, 50, 160, 30);
		jButtonPlugins.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				clickPluginOverview();
			}
		});
		jPanelPlugins.add(jButtonPlugins);
		jButtonPluginsDir = new JButton();
		jButtonPluginsDir.setText("...");
		jButtonPluginsDir.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				selectPluginDir();
			}
		});
		jButtonPluginsDir.setBounds(285, 10, 30, 30);
		jPanelPlugins.add(jButtonPluginsDir);
		jPanelContent.add(jPanelPlugins);

		/** -------------------------Bottom Info---------------------------- */
		jPanelBottom = new JPanel();
		jButtonOK = new JButton();
		jButtonOK.setText("OK");
		jButtonOK.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				saveConfiguration(e);
			}
		});
		jPanelBottom.add(jButtonOK);
		jButtonCancel = new JButton();
		jButtonCancel.setText("Cancel");
		jButtonCancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				closeWindow();
			}
		});
		jPanelBottom.add(jButtonCancel);
		this.getContentPane().add(jPanelBottom, BorderLayout.SOUTH);

		jSplitPaneProperty.setRightComponent(jPanelContent);
		jPanelCenter.add(jSplitPaneProperty, BorderLayout.CENTER);
		this.getContentPane().add(jPanelCenter, BorderLayout.CENTER);

		this.setTitle("JTalk Configuration");
		this.pack();

	}

	/**
	 * 关闭配置窗口.
	 */
	private void closeWindow() {
		this.setupElements();
		this.dispose();
	}

	/**
	 * 设置元素显示.
	 */
	private boolean setupElements() {
		jTextFieldServerIP.setText(this.parent.theClient.serverName);
		jTextFieldServerPort.setText(String.valueOf(this.parent.theClient.serverPort));
		if (this.parent.theClient.useSSL) {
			this.jCheckBoxUseSSL.setSelected(true);
		} else {
			this.jCheckBoxUseSSL.setSelected(false);
		}
		jTextFieldUserName.setText(this.parent.theClient.userName);
		String password = this.parent.theClient.password;
		if (this.parent.theClient.savePassword) {
			jPasswordField.setText(password);
			jCheckBoxSavePassword.setSelected(true);
		} else {
			jCheckBoxSavePassword.setSelected(false);
		}
		jTextFieldBrowser.setText(this.parent.theClient.defaultBrowser);
		jTextFieldMail.setText(this.parent.theClient.defaultMailer);
		int notificationType = 0;
		for (Enumeration<AbstractButton> e = buttonGroupNote.getElements(); e.hasMoreElements();) {
			JRadioButton button = (JRadioButton) e.nextElement();
			if (notificationType == this.parent.theClient.newMailNotificationType) {
				button.setSelected(true);
				break;
			}
			notificationType++;
		}
		if (this.onInit) {
			UIManager.LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
			for (UIManager.LookAndFeelInfo lf : lfs) {
				this.jComboBoxLooks.addItem(lf.getClassName());
			}
			this.jComboBoxLooks.setSelectedItem(this.parent.theClient.guiPlaf);
		}
		this.jButtonTxColor.setBackground(Color.decode(this.parent.theClient.guiTextColor));
		this.jButtonBGColor.setBackground(Color.decode(this.parent.theClient.guiBgColor));
		this.jTextFieldPluginsDir.setText(this.parent.theClient.pluginDir);
		return true;
	}

	@Override
	public void setVisible(boolean visible) {
		this.setupElements();
		super.setVisible(visible);
	}

	/**
	 * 切换配置项时触发的方法.
	 * 
	 * @param e
	 */
	private void listPropertyChanged(ListSelectionEvent e) {
		// TODO Auto-generated method stub
		this.showPropertyPanel(this.jListPropertyPages.getSelectedIndex());
	}

	/**
	 * 保存配置.
	 * 
	 * @param e
	 */
	private void saveConfiguration(ActionEvent e) {
		// TODO Auto-generated method stub
		String user = this.jTextFieldUserName.getText();
		String password = String.valueOf(this.jPasswordField.getPassword());
		String serverIP = this.jTextFieldServerIP.getText();
		String serverPort = this.jTextFieldServerPort.getText();
		String browser = this.jTextFieldBrowser.getText();
		String mailClient = this.jTextFieldMail.getText();
		String guiTextColor = JTalkClient.getColorAsString(this.jButtonTxColor.getBackground());
		String guiBgColor = JTalkClient.getColorAsString(this.jButtonBGColor.getBackground());
		String guiPlaf = (String) this.jComboBoxLooks.getSelectedItem();
		String pluginDir = this.jTextFieldPluginsDir.getText();
		int notificationType = 0;
		for (Enumeration<AbstractButton> en = this.buttonGroupNote.getElements(); en.hasMoreElements();) {
			if (((JRadioButton) en.nextElement()).isSelected()) {
				break;
			}
			notificationType++;
		}
		this.parent.theClient.serverName = serverIP;
		this.parent.theClient.serverPort = Integer.parseInt(serverPort);
		this.parent.theClient.userName = user;
		this.parent.theClient.password = password;
		this.parent.theClient.defaultBrowser = browser;
		this.parent.theClient.defaultMailer = mailClient;
		this.parent.theClient.newMailNotificationType = notificationType;
		this.parent.theClient.guiTextColor = guiTextColor;
		this.parent.theClient.guiBgColor = guiBgColor;
		if (this.jCheckBoxUseSSL.isSelected()) {
			this.parent.theClient.useSSL = true;
		} else {
			this.parent.theClient.useSSL = false;
		}
		if (!guiPlaf.equals(this.parent.theClient.guiPlaf)) {
			try {
				UIManager.setLookAndFeel((String) this.jComboBoxLooks.getSelectedItem());
			} catch (Exception e1) {
				System.out.println("*** Can't set Look'n'Feel!");
			}
			SwingUtilities.updateComponentTreeUI(this.parent);
		}
		this.parent.theClient.pluginDir = pluginDir;
		this.parent.loadAllPlugins();
		if (this.jCheckBoxSavePassword.isSelected()) {
			this.parent.theClient.savePassword = true;
		} else {
			this.parent.theClient.savePassword = false;
		}
		this.parent.theClient.saveSettings();
		this.dispose();
	}

	/**
	 * 切换外观.
	 */
	private void switchLookAndFeel() {
		if (this.onInit) {
			return;
		}
		this.setVisible(false);
		try {
			UIManager.setLookAndFeel((String) this.jComboBoxLooks.getSelectedItem());
			SwingUtilities.updateComponentTreeUI(this);
		} catch (Exception e) {
			System.out.println("*** Can't set Look'n'Feel!");
		}
		this.setVisible(true);
	}

	/**
	 * 设置背景颜色.
	 */
	private void selectBGColor() {
		Color newColor = JColorChooser.showDialog(this.jButtonBGColor, "Choose a custom color",
				this.jButtonBGColor.getBackground());
		if (newColor != null) {
			this.jButtonBGColor.setBackground(newColor);
		}
	}

	/**
	 * 设置文本颜色.
	 */
	private void selectTXColor() {
		Color newColor = JColorChooser.showDialog(this.jButtonTxColor, "Choose a custom color",
				this.jButtonTxColor.getBackground());
		if (newColor != null) {
			this.jButtonTxColor.setBackground(newColor);
		}
	}

	public class MyCellRenderer extends JLabel implements ListCellRenderer {
		private ImageIcon userSettingsIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/user_settings.png"));
		private ImageIcon serverSettingsIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/server.png"));
		private ImageIcon appsSettingsIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/apps.png"));
		private ImageIcon notificationIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/notification.png"));
		private ImageIcon lookIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/look.png"));
		private ImageIcon pluginIcon = new ImageIcon(cl.getResource("com/jtalker/rs/icons/plugins.png"));

		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
				boolean cellHasFocus) {
			if (value == null) {
				return null;
			}
			String rowText = (String) value;
			if (rowText.equals("Login")) {
				this.setIcon(this.userSettingsIcon);
			} else if (rowText.equals("Server")) {
				this.setIcon(this.serverSettingsIcon);
			} else if (rowText.equals("Apps")) {
				this.setIcon(this.appsSettingsIcon);
			} else if (rowText.equals("Notification")) {
				this.setIcon(this.notificationIcon);
			} else if (rowText.equals("Look")) {
				this.setIcon(this.lookIcon);
			} else if (rowText.equals("Plugins")) {
				this.setIcon(this.pluginIcon);
			}
			this.setText(rowText + "  ");
			if (isSelected) {
				this.setBackground(list.getSelectionBackground());
				this.setForeground(list.getSelectionForeground());
			} else {
				this.setBackground(list.getBackground());
				this.setForeground(list.getForeground());
			}
			this.setEnabled(list.isEnabled());
			this.setFont(list.getFont());
			this.setOpaque(true);
			return this;
		}
	}
	
	/**
	 * 点击插件选择按钮.
	 */
	private void clickPluginOverview(){
		if(this.parent.myPluginsInfo == null){
			this.parent.myPluginsInfo = new JTalkClientPluginsInfo(this.parent);
		}
		if(this.parent.myPluginsInfo.updatePluginList(this.jTextFieldPluginsDir.getText())){
			this.parent.myPluginsInfo.setVisible(true);
		}
	}
	
	/**
	 * 选择插件文件夹.
	 */
	public void selectPluginDir(){
		JFileChooser chooser = new JFileChooser();
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		chooser.setCurrentDirectory(new File(this.jTextFieldPluginsDir.getText()));
		int retVal = chooser.showOpenDialog(this);
		if(retVal == JFileChooser.APPROVE_OPTION){
			File f = chooser.getSelectedFile();
			String fileName = f.getAbsolutePath();
			this.jTextFieldPluginsDir.setText(fileName + File.separator);
		}
	}

}
